package com.chenyaowei.web.controller.product.brand;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.chenyaowei.common.annotation.Log;
import com.chenyaowei.common.core.controller.BaseController;
import com.chenyaowei.common.core.domain.AjaxResult;
import com.chenyaowei.common.enums.BusinessType;
import com.chenyaowei.product.domain.CywProductBrand;
import com.chenyaowei.product.service.ICywProductBrandService;
import com.chenyaowei.common.utils.poi.ExcelUtil;
import com.chenyaowei.common.core.page.TableDataInfo;

/**
 * 商品品牌Controller
 *
 * @author 陈耀威
 * @date 2023-11-22
 */
@RestController
@RequestMapping("/product/brand")
public class CywProductBrandController extends BaseController
{
    @Autowired
    private ICywProductBrandService cywProductBrandService;

    /**
     * 查询商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('product:brand:list')")
    @GetMapping("/list")
    public TableDataInfo list(CywProductBrand cywProductBrand)
    {
        startPage();
        List<CywProductBrand> list = cywProductBrandService.selectCywProductBrandList(cywProductBrand);
        return getDataTable(list);
    }

    /**
     * 导出商品品牌列表
     */
    @PreAuthorize("@ss.hasPermi('product:brand:export')")
    @Log(title = "商品品牌", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CywProductBrand cywProductBrand)
    {
        List<CywProductBrand> list = cywProductBrandService.selectCywProductBrandList(cywProductBrand);
        ExcelUtil<CywProductBrand> util = new ExcelUtil<CywProductBrand>(CywProductBrand.class);
        util.exportExcel(response, list, "商品品牌数据");
    }

    /**
     * 获取商品品牌详细信息
     */
    @PreAuthorize("@ss.hasPermi('product:brand:query')")
    @GetMapping(value = "/{brandId}")
    public AjaxResult getInfo(@PathVariable("brandId") Long brandId)
    {
        return success(cywProductBrandService.selectCywProductBrandByBrandId(brandId));
    }

    /**
     * 新增商品品牌
     */
    @PreAuthorize("@ss.hasPermi('product:brand:add')")
    @Log(title = "商品品牌", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CywProductBrand cywProductBrand)
    {
        return toAjax(cywProductBrandService.insertCywProductBrand(cywProductBrand));
    }

    /**
     * 修改商品品牌
     */
    @PreAuthorize("@ss.hasPermi('product:brand:edit')")
    @Log(title = "商品品牌", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CywProductBrand cywProductBrand)
    {
        return toAjax(cywProductBrandService.updateCywProductBrand(cywProductBrand));
    }

    /**
     * 删除商品品牌
     */
    @PreAuthorize("@ss.hasPermi('product:brand:remove')")
    @Log(title = "商品品牌", businessType = BusinessType.DELETE)
	@DeleteMapping("/{brandIds}")
    public AjaxResult remove(@PathVariable Long[] brandIds)
    {
        return toAjax(cywProductBrandService.deleteCywProductBrandByBrandIds(brandIds));
    }
}
